//帖子标签设置





import React, { useState, useEffect, useRef } from 'react';
import { Button, Input, Select, Row, Col, message, Tag } from 'antd';
import UploadFile from '../../Compon/UploadFile';
import Gooutfile from '../../Compon/file/Gooutfile.jsx';
import {
  get_changshiping_list,
  delete_changshiping_list,
} from '../../utils/api';
import Toptitle from '../../Compon/Toptitle';
import Tbale from '../ContentManagement/content_components/Tbale';
export default function PostTag() {
  const [list, setlist] = useState([]);
  const a = async () => {
    const res = await get_changshiping_list();
    setlist(res.data.data);
  };
  useEffect(() => {
    a();
    // console.log(list.map((item: any) => item.changshipinfenlei_beizhu));
    //循环遍历每一个数据
  }, []);
  const columns = [
    {
      title: '序号',
      dataIndex: '_id',
      key: '_id',
      render: (text, record,index) => <div>{index+1}</div>,
    },
    {
      title: '编号',
      dataIndex: '_id',
      key: '_id',
      width: 1,
    },
    {
      //分类名
      title: '分类名',
      dataIndex: 'changshipinfenlei_fenleiming',
      key: 'changshipinfenlei_fenleiming',
      render: (text, record) => <div>分类{text}</div>,
      filterMultiple: true,
      filters: Array.from(
        new Set(list.map((item) => item.changshipinfenlei_fenleiming)),
      ).map((item) => ({
        text: `分类${item}`,
        value: item,
      })),
    },
    {
      title: '上级分类',
      dataIndex: 'changshipinfenlei_shangjifenlie',
      key: 'changshipinfenlei_shangjifenlie',
      render: (text, record) => <div>分类{text}</div>,
      filterMultiple: true,
      filters: Array.from(
        new Set(list.map((item) => item.changshipinfenlei_shangjifenlie)),
      ).map((item) => {
        return {
          text: `分类${item}`,
          value: item,
        };
      }),
      onFilter: (value, record) =>
        record.changshipinfenlei_shangjifenlie === value,
    },
    {
      //zhuangtai
      title: '状态',
      dataIndex: 'changshipinfenlei_state',
      key: 'changshipinfenlei_state',
      render: (text, record) => (
        <Tag color={text === 1 ? 'green' : 'red'}>
          {text === 1 ? '启用' : '禁用'}
        </Tag>
      ),
      filterMultiple: true,
      filters: [
        {
          text: '启用',
          value: 1,
        },
        {
          text: '禁用',
          value: 0,
        },
      ],
      filterSearch: true,
      onFilter: (value, record) => record.changshipinfenlei_state === value,
    },
    {
      title: '备注',
      dataIndex: 'changshipinfenlei_beizhu',
      key: 'changshipinfenlei_beizhu',
    },
    {
      title: '操作',
      dataIndex: '_id',
      key: '_id',
      render: (text, record) => (
        <Button
          type="default"
          danger
          onClick={async () => {
            if (confirm('确定删除吗')) {
              await delete_changshiping_list({ text: record._id });
              a();
              message.success('删除成功');
            } else {
              message.error('取消删除');
            }
          }}
        >
          删除
        </Button>
      ),
    },
  ];
  return (
    <div>
      <Toptitle title="帖子标签设置"> </Toptitle>
      <Tbale data={list} colums={columns} />
      <div style={{ display: 'flex' }}>
        <UploadFile
          name={'导入'}
          // url="http://localhost:3000/CustomerService/index/uploadFile"
        ></UploadFile>

        <Gooutfile data={list}></Gooutfile>
      </div>
    </div>
  );
}
